

/*
 * 
 * 
 *   DO NOT RUN ME
 * 
 * 
 * 
 */


package frontend;

import java.io.Reader;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.log4j.Logger;

import domain.*;
//import gui_classes.*;
import java_persistence.*;
import persistence.*;
import resources.*;
import frontend_gui.*;

@SuppressWarnings("unused")
public class ProgramStart {

	private static SqlSession session = null;
	private static Logger log = Logger.getLogger(ProgramStart.class);
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		try {

			//set up the database connectivity
			
			String myBatis_config = "resources/mybatis-config.xml";
			Reader config_reader = Resources.getResourceAsReader(myBatis_config);
			SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(config_reader);
			session = sessionFactory.openSession();
			
			//define the mappers for db connectivity
			
			AppointmentMapper amap = session.getMapper(AppointmentMapper.class);
			DoctorMapper drmap = session.getMapper(DoctorMapper.class);
			NurseMapper nmap = session.getMapper(NurseMapper.class);
			OrdersMapper ordmap = session.getMapper(OrdersMapper.class);
			PatientMapper pmap = session.getMapper(PatientMapper.class);
			ServicesMapper servmap = session.getMapper(ServicesMapper.class);
			SystemAdministratorMapper samap = session.getMapper(SystemAdministratorMapper.class);
			TreatmentRecordMapper trmap = session.getMapper(TreatmentRecordMapper.class);
			UserMapper umap = session.getMapper(UserMapper.class);
			
			// create the login window and allow the user to login
			// loop until looged in.
			// create a User for the currently logged in user.
			
			List<User> users = umap.get_users();
			
			//User logged_in_user = LoginWindow.main(umap);
			User logged_in_user = LoginWindow.main(users);
			
			
			System.out.println("Logged in user: " + logged_in_user.getName());

			// check if the user is special and create associated objects
			
			// Display the main window based on the user's rights.
			
		}
		catch (Exception e) {
			System.out.println("Exception caught: " + e.getMessage());
			log.info( "Exception caught: " + e.getMessage(), e);
		}
		finally {
			if( session != null) {
				session.close();
			}
		}

		
	}

}
